﻿namespace Numbrella.TaskSamples.PiMonteCarlo
{
	using System;
	using Numbrella.Core;
	
	[Serializable]
	public class Task : TaskBase<ResultContents>
	{
        private readonly long expoPerPortion;

		public Task(long expoPerPortion, int id)
			: base(id)
		{
			this.expoPerPortion = expoPerPortion;
		}

		#region Methods

		protected override ResultContents ReallyPerform()
		{
            Random random = new Random();
            long dropsCount = (long)Math.Floor(Math.Pow(10.0, this.expoPerPortion));
		    long dropsSum = 0;
            for (long i = 0; i < dropsCount; i++)
            {
                double x = random.NextDouble();
                double y = random.NextDouble();
                if (Math.Sqrt((x * x) + (y * y)) < 1.0)
                    dropsSum++;
            }

			return new ResultContents(new decimal(dropsCount), new decimal(dropsSum));
		}

		#endregion
	}
}
